package com.fdb.basic.framework.core.dubbo.filter;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;

/**
 * @description:记录服务调用消耗时间的过滤器
 * @date:2019年1月28日 上午11:21:44
 * @author:hengyh
 */
@Activate(group = Constants.CONSUMER, after = "TraceId")
public class InvokeElaspedFilter implements Filter {
	private static Logger log = LogManager.getLogger("com.irdstudio.basic.framework.core.dubbo.filter");

	@Override
	public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
		long start = System.currentTimeMillis();
		Result result = invoker.invoke(invocation);
		long elaspedTime = System.currentTimeMillis() - start;
		Class<?> module = invoker.getInterface();
		log.info("服务：" + module + ", 耗时：" + elaspedTime + "ms");
		return result;
	}

}
